package com.pucheng.bracelet.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import com.pucheng.bracelet.R
import com.pucheng.bracelet.app.util.click
import kotlinx.android.synthetic.main.dialog_select_userinfo.*
import kotlinx.android.synthetic.main.dialog_time_select.*
import kotlinx.android.synthetic.main.dialog_time_select.tv_cancel
import kotlinx.android.synthetic.main.dialog_time_select.tv_done
import java.text.FieldPosition

class SelectUserInfoDialog(private val mContext: Context,val itemsData: MutableList<String>) :
    Dialog(mContext, R.style.DialogStyle) {

    private var onUserinfoSelectedListener: UserinfoDataSelectedListener? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_select_userinfo)

        tv_cancel.click {
            dismiss()
        }
        tv_done.click {
            dismiss()
        }

        val window = window
        window!!.setGravity(Gravity.BOTTOM)
        val attributes = window.attributes
        window.attributes = attributes
        setCanceledOnTouchOutside(true)
        wv_userinfo.setOnItemSelectedListener { _, data, position ->
            if (onUserinfoSelectedListener != null) {
                onUserinfoSelectedListener!!.onSelectItem(data as String,position)
            }
        }
        wv_userinfo.data = itemsData

    }

    fun setOnItemSelectedListener(itemSelectedListener: UserinfoDataSelectedListener): SelectUserInfoDialog {
        this.onUserinfoSelectedListener = itemSelectedListener
        return this
    }

    interface UserinfoDataSelectedListener {
        fun onSelectItem(data: String,position: Int)
    }

}